<cfimport taglib="/cacheManagement/util/" prefix="cache" />
<html>

	<head>
		
		<link type="text/css" href="/cacheManagement/examples/assets/style.css" rel="stylesheet" />
		<title>Cache Management Examples</title>
		
	</head>
	
	<body>

	<cfscript>
	startTime = getTickCount();
	
	cm = getCacheManager();
	
	if( not cm.exists( 'Computer', 'myComposite' ) ){
		
		// register listeners
		cm.registerListener( 'onCacheAdded', getListener() );
		cm.registerListener( 'onCacheRemoved', getListener() );
		cm.registerListener( 'onElementPut', getListener(), true );
		cm.registerListener( 'onElementExpired', getListener() );
		cm.registerListener( 'onElementRemoved', getListener() );
		cm.registerListener( 'onElementsRemoveAll', getListener() );
		
		message = "set a cache";
	
		c = getFactory().createComputer();
		
		cm.add( 'Computer', 'myComposite', c );
	
	}else{
	
		c = cm.get( 'Computer', 'myComposite' );
		
		message = "get a cache";
	
	}
	
	cache = cm.createCache( 'Test' );
	
	cm.addCache( cache );
	
	element = cm.createElement( 'myKey', 1234556 );
	
	cm.put( 'Test', element );
	
	cm.removeElement( 'Test', 'myKey' );
	
	cm.removeCache( 'Test' );
	
	endTime = getTickCount();
	
	totalExecution = endTime - startTime;
	</cfscript>
	
	<div class="title">Event examples</div>
	
	<p></p>
	
	<textarea cols="60" rows="5" class="code">
	startTime = getTickCount();
	
	cm = getCacheManager();
	
	if( not cm.exists( 'Computer', 'myComposite' ) ){
		
		// register listeners
		cm.registerListener( 'onCacheAdded', getListener() );
		cm.registerListener( 'onCacheRemoved', getListener() );
		cm.registerListener( 'onElementPut', getListener() );
		cm.registerListener( 'onElementExpired', getListener() );
		cm.registerListener( 'onElementRemoved', getListener() );
		cm.registerListener( 'onElementsRemoveAll', getListener() );
		
		message = "set a cache";
	
		c = getFactory().createComputer();
		
		cm.add( 'Computer', 'myComposite', c );
	
	}else{
	
		c = cm.get( 'Computer', 'myComposite' );
		
		message = "get a cache";
	
	}
	
	cache = cm.createCache( 'Test' );
	
	cm.addCache( cache );
	
	element = cm.createElement( 'myKey', 1234556 );
	
	cm.put( 'Test', element );
	
	cm.removeElement( 'Test', 'myKey' );
	
	cm.removeCache( 'Test' );
	
	endTime = getTickCount();
	
	totalExecution = endTime - startTime;
	</textarea><br/>
	
	<br/>
	<p>Command: <cfoutput>#message#</cfoutput>.</p>
	<p>Total execution time: <cfoutput>#totalExecution#</cfoutput> ms</p>
	
	<hr />
	
	<cfset f = getFacade() />

	<div><strong>Event Monitor</strong></div><br />

	<table width="100%">
	
		<tr>
			<td>
				<cfset onCacheAdded = f.getValue('onCacheAdded').iterator() />
				<label>onCacheAdded</label>
				<cfset s = "" />
				<cfloop condition="#onCacheAdded.hasNext()#">
				<cfset s = s & trim( onCacheAdded.next() ) />
				</cfloop>
				<cfoutput>
				<div class="code">
				#s#
				</div>
				</cfoutput>
			</td>
			<td>
				<cfset onCacheRemoved = f.getValue('onCacheRemoved').iterator() />
				<label>onCacheRemoved</label>
				<cfset s = "" />
				<cfloop condition="#onCacheRemoved.hasNext()#">
				<cfset s = s & trim( onCacheRemoved.next() ) />
				</cfloop>
				<cfoutput>
				<div class="code">
				#s#
				</div>
				</cfoutput>
			</td>
		</tr>
		<tr>
			<td>
				<cfset onElementPut = f.getValue('onElementPut').iterator() />
				<label>onElementPut</label>
				<cfset s = "" />
				<cfloop condition="#onElementPut.hasNext()#">
				<cfset s = s & trim( onElementPut.next() ) />
				</cfloop>
				<cfoutput>
				<div class="code">
				#s#
				</div>
				</cfoutput>
			</td>
			<td>
				<cfset onElementExpired = f.getValue('onElementExpired').iterator() />
				<label>onElementExpired</label>
				<cfset s = "" />
				<cfloop condition="#onElementExpired.hasNext()#">
				<cfset s = s & trim( onElementExpired.next() ) />
				</cfloop>
				<cfoutput>
				<div class="code">
				#s#
				</div>
				</cfoutput>
			</td>
		</tr>
		<tr>
			<td>
				<cfset onElementRemoved = f.getValue('onElementRemoved').iterator() />
				<label>onElementRemoved</label>
				<cfset s = "" />
				<cfloop condition="#onElementRemoved.hasNext()#">
				<cfset s = s & trim( onElementRemoved.next() ) />
				</cfloop>
				<cfoutput>
				<div class="code">
				#s#
				</div>
				</cfoutput>
			</td>
			<td>
				<cfset onElementsRemoveAll = f.getValue('onElementsRemoveAll').iterator() />
				<label>onElementsRemoveAll</label>
				<cfset s = "" />
				<cfloop condition="#onElementsRemoveAll.hasNext()#">
				<cfset s = s & trim( onElementsRemoveAll.next() ) />
				</cfloop>
				<cfoutput>
				<div class="code">
				#s#
				</div>
				</cfoutput>
			</td>
		</tr>
	
	</table>
	
	<cache:monitor cacheManager="#cm#" />
	
	<p><a href="../../index.cfm">Back to home</a></p>
	
	</body>

</html>